from __future__ import absolute_import
import logging
from os.path import join
from forest.api import Command, get_tool
logger = logging.getLogger('forest.commands.Shell')

class Shell(Command):
    '''
    DEPRECATED, disabled
    '''

    __register__ = 'commands.setup.Shell'

    requires_config = ['shell']

    def run(self, config):
        self.config = config.get('prompt', None)

        if self.config is None:
            return

        if not isinstance(self.config, basestring):
            raise Exception("prompt should be string.")

        nonlogin_path = config.join_install_root('root', '.bashrc')
        login_path = config.join_install_root('root', '.bash_profile')

        get_tool('files.write')(nonlogin_path, 'export PS1="{prompt}"\n'.format(prompt = self.config))
        get_tool('files.write')(login_path, 'source ~/.bashrc')
